home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 1.iso / toolbox / src / tutorials / custEducation / opengl2 / examples / irisgl_vs_opengl / polygonStipple.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-11-11  |  3.6 KB  |  147 lines

  1. /*
  2.  * Copyright 1993, 1996, Silicon Graphics, Inc.
  3.  * All Rights Reserved.
  4.  *
  5.  * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
  6.  * the contents of this file may not be disclosed to third parties, copied or
  7.  * duplicated in any form, in whole or in part, without the prior written
  8.  * permission of Silicon Graphics, Inc.
  9.  *
  10.  * RESTRICTED RIGHTS LEGEND:
  11.  * Use, duplication or disclosure by the Government is subject to restrictions
  12.  * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
  13.  * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
  14.  * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
  15.  * rights reserved under the Copyright Laws of the United States.
  16.  */
  17.  
  18. /* polygonStipple.c  - open a window, clear the background, and 
  19.  *     render a rectangle with a brick pattern
  20.  *
  21.  *    Escape key    - exit the program
  22.  */
  23. #include <GL/gl.h>
  24. #include <GL/glu.h>
  25. #include <GL/glut.h>
  26.  
  27. #include <math.h>
  28. #include <stdio.h>
  29.  
  30. /* Function Prototypes */
  31.  
  32. GLvoid  initgfx( GLvoid );
  33. GLvoid  drawScene( GLvoid );
  34. GLvoid  reshape( GLsizei, GLsizei );
  35. GLvoid  keyboard( GLubyte, GLint, GLint );
  36.  
  37. void printHelp( char * );
  38.  
  39. /* Global Definitions */
  40.  
  41. #define KEY_ESC    27    /* ascii value for the escape key */
  42.  
  43. void
  44. main( int argc, char *argv[] )
  45. {
  46.     GLsizei     width, height;
  47.  
  48.     glutInit( &argc, argv );
  49.  
  50.     width = glutGet( GLUT_SCREEN_WIDTH ); 
  51.     height = glutGet( GLUT_SCREEN_HEIGHT );
  52.     glutInitWindowPosition( width/4, height/4 ); 
  53.     glutInitWindowSize( width/2, height/2 );
  54.     glutInitDisplayMode( GLUT_RGBA );
  55.     glutCreateWindow( argv[0] );
  56.     
  57.     initgfx();
  58.  
  59.     glutKeyboardFunc( keyboard );
  60.     glutReshapeFunc( reshape );
  61.     glutDisplayFunc( drawScene ); 
  62.  
  63.     printHelp( argv[0] );
  64.  
  65.     glutMainLoop();
  66. }
  67.  
  68. GLvoid
  69. printHelp( char *progname )
  70. {
  71.     fprintf(stdout, "\n%s - demonstrates polygon stippling\n\n"
  72.         "Escape key        - exit the program\n\n",
  73.         progname
  74.     );
  75. }
  76.  
  77. GLvoid
  78. initgfx( GLvoid )
  79. {
  80.     glClearColor( 0.0, 0.0, 0.0, 1.0 );
  81. }
  82.  
  83. GLvoid 
  84. keyboard( GLubyte key, GLint x, GLint y )
  85. {
  86.     switch (key) {
  87.     case KEY_ESC:    /* Exit whenever the Escape key is pressed */
  88.         exit(0);
  89.     }
  90. }
  91.  
  92. GLvoid
  93. reshape( GLsizei width, GLsizei height )
  94. {
  95.     GLdouble    aspect;
  96.  
  97.     glViewport( 0, 0, width, height );
  98.  
  99.     aspect = (GLdouble) width / (GLdouble) height;
  100.  
  101.     glMatrixMode( GL_PROJECTION );
  102.     glLoadIdentity();
  103.         glOrtho( -2.0, 2.0, -2.0, 2.0, -1.0, 1.0 );
  104.     glMatrixMode( GL_MODELVIEW );
  105.     glLoadIdentity();
  106. }
  107.  
  108. /* define a polygon fill pattern for a brick wall */
  109. static GLubyte brick[128] = {
  110.     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
  111.     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
  112.     0xFF, 0xF3, 0xFF, 0xFF, 0xFF, 0xF3, 0xFF, 0xFF, 
  113.     0xFF, 0xF3, 0xFF, 0xFF, 0xFF, 0xF3, 0xFF, 0xFF, 
  114.     0xFF, 0xF3, 0xFF, 0xFF, 0xFF, 0xF3, 0xFF, 0xFF, 
  115.     0xFF, 0xF3, 0xFF, 0xFF, 0xFF, 0xF3, 0xFF, 0xFF, 
  116.     0xFF, 0xF3, 0xFF, 0xFF, 0xFF, 0xF3, 0xFF, 0xFF, 
  117.     0xFF, 0xF3, 0xFF, 0xFF, 0xFF, 0xF3, 0xFF, 0xFF, 
  118.     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
  119.     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
  120.     0xFF, 0xFF, 0xFF, 0xFC, 0xFF, 0xFF, 0xFF, 0xFC,
  121.     0xFF, 0xFF, 0xFF, 0xFC, 0xFF, 0xFF, 0xFF, 0xFC,
  122.     0xFF, 0xFF, 0xFF, 0xFC, 0xFF, 0xFF, 0xFF, 0xFC,
  123.     0xFF, 0xFF, 0xFF, 0xFC, 0xFF, 0xFF, 0xFF, 0xFC,
  124.     0xFF, 0xFF, 0xFF, 0xFC, 0xFF, 0xFF, 0xFF, 0xFC,
  125.     0xFF, 0xFF, 0xFF, 0xFC, 0xFF, 0xFF, 0xFF, 0xFC
  126. };
  127.  
  128. GLvoid
  129. drawScene( GLvoid )
  130. {
  131.     glClear( GL_COLOR_BUFFER_BIT );
  132.  
  133.     /* Draw a white rectangle behind the brick pattern */
  134.     glColor3f( 1.0, 1.0, 1.0 );
  135.     glRectf( -1.0, -1.0, 1.0, 1.0 );
  136.  
  137.     /* Draw a red rectangle with a brick pattern */
  138.     glPolygonStipple( brick );
  139.     glEnable( GL_POLYGON_STIPPLE );
  140.  
  141.     glColor3f( 1.0, 0.0, 0.0 );
  142.     glRectf( -1.0, -1.0, 1.0, 1.0 );
  143.  
  144.     glDisable( GL_POLYGON_STIPPLE );
  145.     glFlush();
  146. }
  147.